using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using PulsePrototype.PulseManagers;
using PulsePrototype.Messages;


namespace PulsePrototype
{
    /// <summary>
    /// This is a game component that an Entity can have.
    /// </summary>
    public abstract class BaseComponent
    {
        private BaseEntity parent;

        public BaseEntity Parent
        {
            get { return parent; }
            set
            {
                if (parent != null)
                    throw new InvalidOperationException("Unable to change parent of entity after it has been set.");
                parent = value;
            }
        }

        public String Name
        {
            get { return this.GetName(); }
        }

        public BaseComponent(BaseEntity parentEntity)
        {
            // TODO: Construct any child components here
            this.parent = parentEntity;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        protected virtual void Initialize()
        {
            // TODO: Add your initialization code here
            // As soon as component is made, add it to the entity parent's ComponentCollection.
            this.parent.AddComponent(this);
        }

        /// <summary>
        /// Allows objects to interact with other objects.
        /// Examples: A physics manager sends a message to the render component to change it's position.
        /// This example may not be accurate.
        /// </summary>
        public virtual bool SendMessage(BaseMessage msg)
        {
            return false;
        }

        protected abstract String GetName();
        public virtual void Update(GameTime gameTime) { }
        public virtual void Draw(GameTime gameTime, List<RenderDescription> renderDescriptions) { }

    }
}
